{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import random\n",
    "from sklearn.neighbors import NearestNeighbors\n",
    "from scipy import ndarray"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename='preprocessed_majority.csv'\n",
    "datapd_0=pd.read_csv(filename, index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename='preprocessed_minority.csv'\n",
    "datapd_1=pd.read_csv(filename, index_col=0 )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Majority class dataframe shape: (16383, 23)\n",
      "Minority class dataframe shape: (625, 23)\n"
     ]
    }
   ],
   "source": [
    "print('Majority class dataframe shape:', datapd_0.shape)\n",
    "print('Minority class dataframe shape:', datapd_1.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "n_feat=datapd_0.shape[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Imbalance Ratio: 26.2128\n"
     ]
    }
   ],
   "source": [
    "print('Imbalance Ratio:', datapd_0.shape[0]/datapd_1.shape[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "features_0=np.asarray(datapd_0)\n",
    "features_1=np.asarray(datapd_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "s=93\n",
    "features_1=np.take(features_1,np.random.RandomState(seed=s).permutation(features_1.shape[0]),axis=0,out=features_1)\n",
    "features_0=np.take(features_0,np.random.RandomState(seed=s).permutation(features_0.shape[0]),axis=0,out=features_0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "a=len(features_1)//3\n",
    "b=len(features_0)//3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_1_min=features_1[0:a]\n",
    "fold_1_maj=features_0[0:b]\n",
    "fold_1_tst=np.concatenate((fold_1_min,fold_1_maj))\n",
    "lab_1_tst=np.concatenate((np.zeros(len(fold_1_min))+1, np.zeros(len(fold_1_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_2_min=features_1[a:2*a]\n",
    "fold_2_maj=features_0[b:2*b]\n",
    "fold_2_tst=np.concatenate((fold_2_min,fold_2_maj))\n",
    "lab_2_tst=np.concatenate((np.zeros(len(fold_1_min))+1, np.zeros(len(fold_1_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_3_min=features_1[2*a:]\n",
    "fold_3_maj=features_0[2*b:]\n",
    "fold_3_tst=np.concatenate((fold_3_min,fold_3_maj))\n",
    "lab_3_tst=np.concatenate((np.zeros(len(fold_3_min))+1, np.zeros(len(fold_3_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_1_trn=np.concatenate((fold_2_min,fold_3_min,fold_2_maj,fold_3_maj))\n",
    "lab_1_trn=np.concatenate((np.zeros(a+len(fold_3_min))+1,np.zeros(b+len(fold_3_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_2_trn=np.concatenate((fold_1_min,fold_3_min,fold_1_maj,fold_3_maj))\n",
    "lab_2_trn=np.concatenate((np.zeros(a+len(fold_3_min))+1,np.zeros(b+len(fold_3_maj))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "fold_3_trn=np.concatenate((fold_2_min,fold_1_min,fold_2_maj,fold_1_maj))\n",
    "lab_3_trn=np.concatenate((np.zeros(2*a)+1,np.zeros(2*b)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "training_folds_feats=[fold_1_trn,fold_2_trn,fold_3_trn]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "testing_folds_feats=[fold_1_tst,fold_2_tst,fold_3_tst]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "training_folds_labels=[lab_1_trn,lab_2_trn,lab_3_trn]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "testing_folds_labels=[lab_1_tst,lab_2_tst,lab_3_tst]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "def lr(X_train,y_train,X_test,y_test):\n",
    "    from sklearn import metrics\n",
    "    from sklearn.linear_model import LogisticRegression\n",
    "    from sklearn.metrics import confusion_matrix\n",
    "    from sklearn.metrics import f1_score\n",
    "    from sklearn.metrics import precision_score\n",
    "    from sklearn.metrics import recall_score\n",
    "    from sklearn.metrics import balanced_accuracy_score\n",
    "    logreg = LogisticRegression(C=1e5, solver='lbfgs', multi_class='multinomial', class_weight={0: 1, 1: 1})\n",
    "    logreg.fit(X_train, y_train)\n",
    "    y_pred= logreg.predict(X_test)\n",
    "    con_mat=confusion_matrix(y_test,y_pred)\n",
    "    bal_acc=balanced_accuracy_score(y_test,y_pred)\n",
    "    tn, fp, fn, tp = con_mat.ravel()\n",
    "    print('tn, fp, fn, tp:', tn, fp, fn, tp)\n",
    "    f1 = f1_score(y_test, y_pred)\n",
    "    precision=precision_score(y_test, y_pred)\n",
    "    recall=recall_score(y_test, y_pred)\n",
    "    print('balanced accuracy_LR:', bal_acc)\n",
    "    print('f1 score_LR:', f1)\n",
    "    print('confusion matrix_LR',con_mat)\n",
    "    return(f1, bal_acc, precision, recall, con_mat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "def svm(X_train,y_train,X_test,y_test):\n",
    "    from sklearn import preprocessing\n",
    "    from sklearn import metrics\n",
    "    #from sklearn import svm\n",
    "    from sklearn.svm import LinearSVC\n",
    "    from sklearn.metrics import confusion_matrix\n",
    "    from sklearn.metrics import f1_score\n",
    "    from sklearn.metrics import precision_score\n",
    "    from sklearn.metrics import recall_score\n",
    "    from sklearn.metrics import balanced_accuracy_score\n",
    "    X_train = preprocessing.scale(X_train)\n",
    "    X_test = preprocessing.scale(X_test)\n",
    "    #svm= svm.SVC(kernel='linear', decision_function_shape='ovo', class_weight={0: 1., 1: 1.},probability=True)\n",
    "    svm= LinearSVC(random_state=0, tol=1e-5)\n",
    "    svm.fit(X_train, y_train)\n",
    "    y_pred= svm.predict(X_test)\n",
    "    con_mat=confusion_matrix(y_test,y_pred)\n",
    "    bal_acc=balanced_accuracy_score(y_test,y_pred)\n",
    "    tn, fp, fn, tp = con_mat.ravel()\n",
    "    print('tn, fp, fn, tp:', tn, fp, fn, tp)\n",
    "    f1 = f1_score(y_test, y_pred)\n",
    "    precision=precision_score(y_test, y_pred)\n",
    "    recall=recall_score(y_test, y_pred)\n",
    "    print('balanced accuracy_SVM:', bal_acc)\n",
    "    print('f1 score_SVM:', f1)\n",
    "    print('confusion matrix_SVM',con_mat)\n",
    "    return( f1, bal_acc, precision, recall, con_mat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "def knn(X_train,y_train,X_test,y_test):\n",
    "    from sklearn import metrics\n",
    "    from sklearn.neighbors import KNeighborsClassifier\n",
    "    from sklearn.metrics import confusion_matrix\n",
    "    from sklearn.metrics import f1_score\n",
    "    from sklearn.metrics import precision_score\n",
    "    from sklearn.metrics import recall_score   \n",
    "    from sklearn.metrics import balanced_accuracy_score\n",
    "    knn = KNeighborsClassifier(n_neighbors=10)\n",
    "    knn.fit(X_train, y_train)\n",
    "    y_pred= knn.predict(X_test)\n",
    "    con_mat=confusion_matrix(y_test,y_pred)\n",
    "    bal_acc=balanced_accuracy_score(y_test,y_pred)\n",
    "    tn, fp, fn, tp = con_mat.ravel()\n",
    "    print('tn, fp, fn, tp:', tn, fp, fn, tp)\n",
    "    print('balanced accuracy_KNN:', bal_acc)\n",
    "    f1 = f1_score(y_test, y_pred)\n",
    "    precision=precision_score(y_test, y_pred)\n",
    "    recall=recall_score(y_test, y_pred)\n",
    "    print('f1 score_KNN:', f1)\n",
    "    print('confusion matrix_KNN',con_mat)\n",
    "    return(f1, bal_acc, precision, recall, con_mat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Neb_grps(data,near_neb):\n",
    "    nbrs = NearestNeighbors(n_neighbors=near_neb, algorithm='ball_tree').fit(data)\n",
    "    distances, indices = nbrs.kneighbors(data)\n",
    "    neb_class=[]\n",
    "    for i in (indices):\n",
    "        neb_class.append(i)\n",
    "    return(np.asarray(neb_class)) \n",
    "\n",
    "def LoRAS(data,num_samples,shadow,sigma,num_RACOS,num_afcomb):\n",
    "    np.random.seed(42)\n",
    "    data_shadow=([])\n",
    "    for i in range (num_samples):\n",
    "        c=0\n",
    "        while c<shadow:\n",
    "            data_shadow.append(data[i]+np.random.normal(0,sigma))\n",
    "            c=c+1\n",
    "    data_shadow==np.asarray(data_shadow)\n",
    "    data_shadow_lc=([])\n",
    "    for i in range(num_RACOS):\n",
    "        idx = np.random.randint(shadow*num_samples, size=num_afcomb)\n",
    "        w=np.random.randint(100, size=len(idx))\n",
    "        aff_w=np.asarray(w/sum(w))\n",
    "        data_tsl=np.array(data_shadow)[idx,:]\n",
    "        data_tsl_=np.dot(aff_w, data_tsl)\n",
    "        data_shadow_lc.append(data_tsl_)\n",
    "    return(np.asarray(data_shadow_lc))   \n",
    "\n",
    "def LoRAS_gen(num_samples,shadow,sigma,num_RACOS,num_afcomb):\n",
    "    RACOS_set=[]\n",
    "    for i in range (len(nb_list)):\n",
    "        RACOS_i= LoRAS(features_1_trn[nb_list[i]],num_samples,shadow,sigma,num_RACOS,num_afcomb)\n",
    "        RACOS_set.append(RACOS_i)\n",
    "    LoRAS_set=np.asarray(RACOS_set)\n",
    "    LoRAS_1=np.reshape(LoRAS_set,(len(features_1_trn)*num_RACOS,n_feat))\n",
    "    return(np.concatenate((LoRAS_1,features_1_trn)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "def OVS(training_data,training_labels,neb):\n",
    "    from imblearn.over_sampling import SMOTE \n",
    "    sm = SMOTE(random_state=62, k_neighbors=neb,  kind='regular',ratio=1)\n",
    "    SMOTE_feat, SMOTE_labels = sm.fit_resample(training_data,training_labels)\n",
    "    smbl1 = SMOTE(random_state=62, k_neighbors=neb,  kind='borderline1',ratio=1)\n",
    "    SMOTE_feat_bl1, SMOTE_labels_bl1 = smbl1.fit_resample(training_data,training_labels)\n",
    "    smbl2 = SMOTE(random_state=62, k_neighbors=neb,  kind='borderline2',ratio=1)\n",
    "    SMOTE_feat_bl2, SMOTE_labels_bl2 = smbl2.fit_resample(training_data,training_labels)\n",
    "    smsvm = SMOTE(random_state=62, k_neighbors=neb,  kind='svm',ratio=1)\n",
    "    SMOTE_feat_svm, SMOTE_labels_svm = smsvm.fit_resample(training_data,training_labels)\n",
    "    from imblearn.over_sampling import ADASYN\n",
    "    ad = ADASYN(random_state=62,n_neighbors=neb,  ratio=1)\n",
    "    ADASYN_feat, ADASYN_labels = ad.fit_resample(training_data,training_labels)\n",
    "    return(SMOTE_feat, SMOTE_labels,SMOTE_feat_bl1, SMOTE_labels_bl1, SMOTE_feat_bl2, SMOTE_labels_bl2,SMOTE_feat_svm, SMOTE_labels_svm,ADASYN_feat, ADASYN_labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.neighbors.base module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.neighbors. Anything that cannot be imported from sklearn.neighbors is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.ensemble.bagging module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.ensemble. Anything that cannot be imported from sklearn.ensemble is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.ensemble.base module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.ensemble. Anything that cannot be imported from sklearn.ensemble is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.ensemble.forest module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.ensemble. Anything that cannot be imported from sklearn.ensemble is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "Using TensorFlow backend.\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.utils.testing module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.utils. Anything that cannot be imported from sklearn.utils is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:143: FutureWarning: The sklearn.metrics.classification module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.metrics. Anything that cannot be imported from sklearn.metrics is now part of the private API.\n",
      "  warnings.warn(message, FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5432 29 59 149\n",
      "balanced accuracy_LR: 0.8555178855661826\n",
      "f1 score_LR: 0.772020725388601\n",
      "confusion matrix_LR [[5432   29]\n",
      " [  59  149]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5433 28 64 144\n",
      "balanced accuracy_SVM: 0.8435902131196034\n",
      "f1 score_SVM: 0.7578947368421053\n",
      "confusion matrix_SVM [[5433   28]\n",
      " [  64  144]]\n",
      "tn, fp, fn, tp: 5443 18 36 172\n",
      "balanced accuracy_KNN: 0.911813488653811\n",
      "f1 score_KNN: 0.8643216080402011\n",
      "confusion matrix_KNN [[5443   18]\n",
      " [  36  172]]\n",
      "tn, fp, fn, tp: 5287 174 17 191\n",
      "balanced accuracy_LR: 0.9432034672432493\n",
      "f1 score_LR: 0.6666666666666665\n",
      "confusion matrix_LR [[5287  174]\n",
      " [  17  191]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 3791 1670 1 207\n",
      "balanced accuracy_SVM: 0.8446937550181004\n",
      "f1 score_SVM: 0.1985611510791367\n",
      "confusion matrix_SVM [[3791 1670]\n",
      " [   1  207]]\n",
      "tn, fp, fn, tp: 5364 97 10 198\n",
      "balanced accuracy_KNN: 0.9670803811643401\n",
      "f1 score_KNN: 0.7872763419483101\n",
      "confusion matrix_KNN [[5364   97]\n",
      " [  10  198]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5163 298 14 194\n",
      "balanced accuracy_LR: 0.9390617736959982\n",
      "f1 score_LR: 0.5542857142857143\n",
      "confusion matrix_LR [[5163  298]\n",
      " [  14  194]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4057 1404 1 207\n",
      "balanced accuracy_SVM: 0.8690482688434071\n",
      "f1 score_SVM: 0.22759758108851016\n",
      "confusion matrix_SVM [[4057 1404]\n",
      " [   1  207]]\n",
      "tn, fp, fn, tp: 5318 143 9 199\n",
      "balanced accuracy_KNN: 0.965272544476216\n",
      "f1 score_KNN: 0.7236363636363636\n",
      "confusion matrix_KNN [[5318  143]\n",
      " [   9  199]]\n",
      "tn, fp, fn, tp: 4968 493 6 202\n",
      "balanced accuracy_LR: 0.9404386700097193\n",
      "f1 score_LR: 0.44739756367663347\n",
      "confusion matrix_LR [[4968  493]\n",
      " [   6  202]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4057 1404 1 207\n",
      "balanced accuracy_SVM: 0.8690482688434071\n",
      "f1 score_SVM: 0.22759758108851016\n",
      "confusion matrix_SVM [[4057 1404]\n",
      " [   1  207]]\n",
      "tn, fp, fn, tp: 5279 182 9 199\n",
      "balanced accuracy_KNN: 0.9617017698928063\n",
      "f1 score_KNN: 0.6757215619694397\n",
      "confusion matrix_KNN [[5279  182]\n",
      " [   9  199]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5195 266 13 195\n",
      "balanced accuracy_LR: 0.9443954861746933\n",
      "f1 score_LR: 0.5829596412556054\n",
      "confusion matrix_LR [[5195  266]\n",
      " [  13  195]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4144 1317 1 207\n",
      "balanced accuracy_SVM: 0.8770138429140901\n",
      "f1 score_SVM: 0.23903002309468824\n",
      "confusion matrix_SVM [[4144 1317]\n",
      " [   1  207]]\n",
      "tn, fp, fn, tp: 5342 119 10 198\n",
      "balanced accuracy_KNN: 0.9650660980660064\n",
      "f1 score_KNN: 0.7542857142857143\n",
      "confusion matrix_KNN [[5342  119]\n",
      " [  10  198]]\n",
      "tn, fp, fn, tp: 5150 311 11 197\n",
      "balanced accuracy_LR: 0.9450830539630668\n",
      "f1 score_LR: 0.5502793296089385\n",
      "confusion matrix_LR [[5150  311]\n",
      " [  11  197]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 3790 1671 1 207\n",
      "balanced accuracy_SVM: 0.8446021966954489\n",
      "f1 score_SVM: 0.1984659635666347\n",
      "confusion matrix_SVM [[3790 1671]\n",
      " [   1  207]]\n",
      "tn, fp, fn, tp: 5302 159 8 200\n",
      "balanced accuracy_KNN: 0.9662114574676377\n",
      "f1 score_KNN: 0.7054673721340388\n",
      "confusion matrix_KNN [[5302  159]\n",
      " [   8  200]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5435 26 51 157\n",
      "balanced accuracy_LR: 0.8750233297649064\n",
      "f1 score_LR: 0.8030690537084398\n",
      "confusion matrix_LR [[5435   26]\n",
      " [  51  157]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5429 32 49 159\n",
      "balanced accuracy_SVM: 0.8792816721366895\n",
      "f1 score_SVM: 0.7969924812030075\n",
      "confusion matrix_SVM [[5429   32]\n",
      " [  49  159]]\n",
      "tn, fp, fn, tp: 5448 13 40 168\n",
      "balanced accuracy_KNN: 0.9026558956516839\n",
      "f1 score_KNN: 0.8637532133676092\n",
      "confusion matrix_KNN [[5448   13]\n",
      " [  40  168]]\n",
      "tn, fp, fn, tp: 5249 212 8 200\n",
      "balanced accuracy_LR: 0.9613588663671067\n",
      "f1 score_LR: 0.6451612903225807\n",
      "confusion matrix_LR [[5249  212]\n",
      " [   8  200]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 3827 1634 0 208\n",
      "balanced accuracy_SVM: 0.8503937007874016\n",
      "f1 score_SVM: 0.20292682926829267\n",
      "confusion matrix_SVM [[3827 1634]\n",
      " [   0  208]]\n",
      "tn, fp, fn, tp: 5352 109 15 193\n",
      "balanced accuracy_KNN: 0.9539624505232911\n",
      "f1 score_KNN: 0.7568627450980393\n",
      "confusion matrix_KNN [[5352  109]\n",
      " [  15  193]]\n",
      "tn, fp, fn, tp: 5163 298 6 202\n",
      "balanced accuracy_LR: 0.9582925429267675\n",
      "f1 score_LR: 0.5706214689265536\n",
      "confusion matrix_LR [[5163  298]\n",
      " [   6  202]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4069 1392 1 207\n",
      "balanced accuracy_SVM: 0.8701469687152255\n",
      "f1 score_SVM: 0.22910902047592693\n",
      "confusion matrix_SVM [[4069 1392]\n",
      " [   1  207]]\n",
      "tn, fp, fn, tp: 5339 122 12 196\n",
      "balanced accuracy_KNN: 0.9599837307903596\n",
      "f1 score_KNN: 0.7452471482889733\n",
      "confusion matrix_KNN [[5339  122]\n",
      " [  12  196]]\n",
      "tn, fp, fn, tp: 5016 445 4 204\n",
      "balanced accuracy_LR: 0.9496411618046849\n",
      "f1 score_LR: 0.4760793465577597\n",
      "confusion matrix_LR [[5016  445]\n",
      " [   4  204]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4069 1392 1 207\n",
      "balanced accuracy_SVM: 0.8701469687152255\n",
      "f1 score_SVM: 0.22910902047592693\n",
      "confusion matrix_SVM [[4069 1392]\n",
      " [   1  207]]\n",
      "tn, fp, fn, tp: 5293 168 12 196\n",
      "balanced accuracy_KNN: 0.9557720479483893\n",
      "f1 score_KNN: 0.6853146853146853\n",
      "confusion matrix_KNN [[5293  168]\n",
      " [  12  196]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5180 281 7 201\n",
      "balanced accuracy_LR: 0.9574451882579973\n",
      "f1 score_LR: 0.582608695652174\n",
      "confusion matrix_LR [[5180  281]\n",
      " [   7  201]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4188 1273 2 206\n",
      "balanced accuracy_SVM: 0.8786385629569113\n",
      "f1 score_SVM: 0.24422050978067575\n",
      "confusion matrix_SVM [[4188 1273]\n",
      " [   2  206]]\n",
      "tn, fp, fn, tp: 5356 105 14 194\n",
      "balanced accuracy_KNN: 0.9567325299677434\n",
      "f1 score_KNN: 0.7652859960552268\n",
      "confusion matrix_KNN [[5356  105]\n",
      " [  14  194]]\n",
      "tn, fp, fn, tp: 5142 319 7 201\n",
      "balanced accuracy_LR: 0.9539659719972391\n",
      "f1 score_LR: 0.5521978021978022\n",
      "confusion matrix_LR [[5142  319]\n",
      " [   7  201]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 3924 1537 0 208\n",
      "balanced accuracy_SVM: 0.8592748580845999\n",
      "f1 score_SVM: 0.21300563236047107\n",
      "confusion matrix_SVM [[3924 1537]\n",
      " [   0  208]]\n",
      "tn, fp, fn, tp: 5288 173 13 195\n",
      "balanced accuracy_KNN: 0.9529104101812855\n",
      "f1 score_KNN: 0.6770833333333333\n",
      "confusion matrix_KNN [[5288  173]\n",
      " [  13  195]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n",
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\deprecation.py:86: FutureWarning: Function safe_indexing is deprecated; safe_indexing is deprecated in version 0.22 and will be removed in version 0.24.\n",
      "  warnings.warn(msg, category=FutureWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5447 14 47 162\n",
      "balanced accuracy_LR: 0.8862779920953188\n",
      "f1 score_LR: 0.8415584415584416\n",
      "confusion matrix_LR [[5447   14]\n",
      " [  47  162]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5450 11 61 148\n",
      "balanced accuracy_SVM: 0.8530598440967663\n",
      "f1 score_SVM: 0.8043478260869567\n",
      "confusion matrix_SVM [[5450   11]\n",
      " [  61  148]]\n",
      "tn, fp, fn, tp: 5444 17 37 172\n",
      "balanced accuracy_KNN: 0.9099267621034408\n",
      "f1 score_KNN: 0.864321608040201\n",
      "confusion matrix_KNN [[5444   17]\n",
      " [  37  172]]\n",
      "tn, fp, fn, tp: 5252 209 12 197\n",
      "balanced accuracy_LR: 0.9521561765945386\n",
      "f1 score_LR: 0.640650406504065\n",
      "confusion matrix_LR [[5252  209]\n",
      " [  12  197]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 3775 1686 1 208\n",
      "balanced accuracy_SVM: 0.8432403235119144\n",
      "f1 score_SVM: 0.19781264859724204\n",
      "confusion matrix_SVM [[3775 1686]\n",
      " [   1  208]]\n",
      "tn, fp, fn, tp: 5341 120 9 200\n",
      "balanced accuracy_KNN: 0.9674819008033476\n",
      "f1 score_KNN: 0.7561436672967864\n",
      "confusion matrix_KNN [[5341  120]\n",
      " [   9  200]]\n",
      "tn, fp, fn, tp: 5149 312 10 199\n",
      "balanced accuracy_LR: 0.9475103583566464\n",
      "f1 score_LR: 0.5527777777777777\n",
      "confusion matrix_LR [[5149  312]\n",
      " [  10  199]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4062 1399 2 207\n",
      "balanced accuracy_SVM: 0.8671252176152955\n",
      "f1 score_SVM: 0.22809917355371898\n",
      "confusion matrix_SVM [[4062 1399]\n",
      " [   2  207]]\n",
      "tn, fp, fn, tp: 5307 154 7 202\n",
      "balanced accuracy_KNN: 0.969153606828411\n",
      "f1 score_KNN: 0.7150442477876107\n",
      "confusion matrix_KNN [[5307  154]\n",
      " [   7  202]]\n",
      "tn, fp, fn, tp: 5009 452 8 201\n",
      "balanced accuracy_LR: 0.9394768821806476\n",
      "f1 score_LR: 0.4663573085846868\n",
      "confusion matrix_LR [[5009  452]\n",
      " [   8  201]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4062 1399 2 207\n",
      "balanced accuracy_SVM: 0.8671252176152955\n",
      "f1 score_SVM: 0.22809917355371898\n",
      "confusion matrix_SVM [[4062 1399]\n",
      " [   2  207]]\n",
      "tn, fp, fn, tp: 5267 194 6 203\n",
      "balanced accuracy_KNN: 0.9678836184199574\n",
      "f1 score_KNN: 0.66996699669967\n",
      "confusion matrix_KNN [[5267  194]\n",
      " [   6  203]]\n",
      "tn, fp, fn, tp: 5152 309 8 201\n",
      "balanced accuracy_LR: 0.9525697223198163\n",
      "f1 score_LR: 0.5591098748261475\n",
      "confusion matrix_LR [[5152  309]\n",
      " [   8  201]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4121 1340 1 208\n",
      "balanced accuracy_SVM: 0.8749195031493434\n",
      "f1 score_SVM: 0.23676721684689814\n",
      "confusion matrix_SVM [[4121 1340]\n",
      " [   1  208]]\n",
      "tn, fp, fn, tp: 5325 136 7 202\n",
      "balanced accuracy_KNN: 0.9708016566361385\n",
      "f1 score_KNN: 0.7385740402193784\n",
      "confusion matrix_KNN [[5325  136]\n",
      " [   7  202]]\n",
      "tn, fp, fn, tp: 5109 352 9 200\n",
      "balanced accuracy_LR: 0.9462403699481929\n",
      "f1 score_LR: 0.5256241787122208\n",
      "confusion matrix_LR [[5109  352]\n",
      " [   9  200]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 3850 1611 1 208\n",
      "balanced accuracy_SVM: 0.850107197710779\n",
      "f1 score_SVM: 0.20512820512820512\n",
      "confusion matrix_SVM [[3850 1611]\n",
      " [   1  208]]\n",
      "tn, fp, fn, tp: 5292 169 6 203\n",
      "balanced accuracy_KNN: 0.9701725764862457\n",
      "f1 score_KNN: 0.6987951807228915\n",
      "confusion matrix_KNN [[5292  169]\n",
      " [   6  203]]\n"
     ]
    }
   ],
   "source": [
    "LR=[]\n",
    "SVM=[]\n",
    "KNN=[] \n",
    "LR_SM=[]\n",
    "SVM_SM=[]\n",
    "KNN_SM=[]\n",
    "LR_SMBL1=[]\n",
    "SVM_SMBL1=[]\n",
    "KNN_SMBL1=[] \n",
    "LR_SMBL2=[]\n",
    "SVM_SMBL2=[]\n",
    "KNN_SMBL2=[] \n",
    "LR_SMSVM=[]\n",
    "SVM_SMSVM=[]\n",
    "KNN_SMSVM=[] \n",
    "LR_ADA=[]\n",
    "SVM_ADA=[]\n",
    "KNN_ADA=[] \n",
    "\n",
    "i=0\n",
    "while i<3:\n",
    "    SMOTE_feat, SMOTE_labels,SMOTE_feat_bl1, SMOTE_labels_bl1, SMOTE_feat_bl2, SMOTE_labels_bl2,SMOTE_feat_svm, SMOTE_labels_svm,ADASYN_feat, ADASYN_labels=OVS(training_folds_feats[i],training_folds_labels[i],30)\n",
    "    \n",
    "    f1_lr, bal_acc_lr, precision_lr, recall_lr, mat_lr=lr(training_folds_feats[i],training_folds_labels[i],testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR.append([f1_lr, bal_acc_lr, precision_lr, recall_lr])\n",
    "    f1_svm,bal_acc_svm,precision_svm, recall_svm,mat_svm=svm(training_folds_feats[i],training_folds_labels[i],testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM.append([f1_svm,bal_acc_svm,precision_svm, recall_svm])\n",
    "    f1_knn,bal_acc_knn,precision_knn, recall_knn,mat_knn=knn(training_folds_feats[i],training_folds_labels[i],testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN.append([f1_knn,bal_acc_knn,precision_knn, recall_knn])\n",
    "    \n",
    "    f1_lr_SMOTE,bal_acc_lr_SMOTE,precision_lr_SMOTE, recall_lr_SMOTE,mat_lr_SMOTE=lr(SMOTE_feat,SMOTE_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_SM.append([f1_lr_SMOTE,bal_acc_lr_SMOTE,precision_lr_SMOTE, recall_lr_SMOTE])\n",
    "    f1_svm_SMOTE,bal_acc_svm_SMOTE,precision_svm_SMOTE, recall_svm_SMOTE,mat_svm_SMOTE=svm(SMOTE_feat,SMOTE_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_SM.append([f1_svm_SMOTE,bal_acc_svm_SMOTE,precision_svm_SMOTE, recall_svm_SMOTE])\n",
    "    f1_knn_SMOTE,bal_acc_knn_SMOTE,precision_knn_SMOTE, recall_knn_SMOTE,mat_knn_SMOTE=knn(SMOTE_feat,SMOTE_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_SM.append([f1_knn_SMOTE,bal_acc_knn_SMOTE,precision_knn_SMOTE, recall_knn_SMOTE])\n",
    "    \n",
    "    f1_lr_SMOTE_bl1,bal_acc_lr_SMOTE_bl1,precision_lr_SMOTE_bl1, recall_lr_SMOTE_bl1,mat_lr_SMOTE_bl1=lr(SMOTE_feat_bl1,SMOTE_labels_bl1,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_SMBL1.append([f1_lr_SMOTE_bl1,bal_acc_lr_SMOTE_bl1,precision_lr_SMOTE_bl1, recall_lr_SMOTE_bl1])\n",
    "    f1_svm_SMOTE_bl1,bal_acc_svm_SMOTE_bl1,precision_svm_SMOTE_bl1, recall_svm_SMOTE_bl1,mat_svm_SMOTE_bl1=svm(SMOTE_feat_bl1,SMOTE_labels_bl1,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_SMBL1.append([f1_svm_SMOTE_bl1,bal_acc_svm_SMOTE_bl1,precision_svm_SMOTE_bl1, recall_svm_SMOTE_bl1])\n",
    "    f1_knn_SMOTE_bl1,bal_acc_knn_SMOTE_bl1,precision_knn_SMOTE_bl1, recall_knn_SMOTE_bl1,mat_knn_SMOTE_bl1=knn(SMOTE_feat_bl1,SMOTE_labels_bl1,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_SMBL1.append([f1_knn_SMOTE_bl1,bal_acc_knn_SMOTE_bl1,precision_knn_SMOTE_bl1, recall_knn_SMOTE_bl1])\n",
    "    \n",
    "    \n",
    "    f1_lr_SMOTE_bl2,bal_acc_lr_SMOTE_bl2,precision_lr_SMOTE_bl2, recall_lr_SMOTE_bl2,mat_lr_SMOTE_bl2=lr(SMOTE_feat_bl2,SMOTE_labels_bl2,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_SMBL2.append([f1_lr_SMOTE_bl2,bal_acc_lr_SMOTE_bl2,precision_lr_SMOTE_bl2, recall_lr_SMOTE_bl2])\n",
    "    f1_svm_SMOTE_bl2,bal_acc_svm_SMOTE_bl2,precision_svm_SMOTE_bl2, recall_svm_SMOTE_bl2,mat_svm_SMOTE_bl2=svm(SMOTE_feat_bl1,SMOTE_labels_bl1,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_SMBL2.append([f1_svm_SMOTE_bl2,bal_acc_svm_SMOTE_bl2,precision_svm_SMOTE_bl2, recall_svm_SMOTE_bl2])\n",
    "    f1_knn_SMOTE_bl2,bal_acc_knn_SMOTE_bl2,precision_knn_SMOTE_bl2, recall_knn_SMOTE_bl2,mat_knn_SMOTE_bl2=knn(SMOTE_feat_bl2,SMOTE_labels_bl2,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_SMBL2.append([f1_knn_SMOTE_bl2,bal_acc_knn_SMOTE_bl2,precision_knn_SMOTE_bl2, recall_knn_SMOTE_bl2])\n",
    "    \n",
    "    f1_lr_SMOTE_svm,bal_acc_lr_SMOTE_svm,precision_lr_SMOTE_svm, recall_lr_SMOTE_svm,mat_lr_SMOTE_svm=lr(SMOTE_feat_svm,SMOTE_labels_svm,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_SMSVM.append([f1_lr_SMOTE_svm,bal_acc_lr_SMOTE_svm,precision_lr_SMOTE_svm, recall_lr_SMOTE_svm])\n",
    "    f1_svm_SMOTE_svm,bal_acc_svm_SMOTE_svm,precision_svm_SMOTE_svm, recall_svm_SMOTE_svm,mat_svm_SMOTE_svm=svm(SMOTE_feat_svm,SMOTE_labels_svm,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_SMSVM.append([f1_svm_SMOTE_svm,bal_acc_svm_SMOTE_svm,precision_svm_SMOTE_svm, recall_svm_SMOTE_svm])\n",
    "    f1_knn_SMOTE_svm,bal_acc_knn_SMOTE_svm,precision_knn_SMOTE_svm, recall_knn_SMOTE_svm,mat_knn_SMOTE_svm=knn(SMOTE_feat_svm,SMOTE_labels_svm,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_SMSVM.append([f1_knn_SMOTE_svm,bal_acc_knn_SMOTE_svm,precision_knn_SMOTE_svm, recall_knn_SMOTE_svm])\n",
    "    \n",
    "    f1_lr_ADASYN,bal_acc_lr_ADASYN,precision_lr_ADASYN, recall_lr_ADASYN,mat_lr_ADASYN=lr(ADASYN_feat,ADASYN_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_ADA.append([f1_lr_ADASYN,bal_acc_lr_ADASYN,precision_lr_ADASYN, recall_lr_ADASYN])\n",
    "    f1_svm_ADASYN,bal_acc_svm_ADASYN,precision_svm_ADASYN, recall_svm_ADASYN,mat_svm_ADASYN=svm(ADASYN_feat,ADASYN_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_ADA.append([f1_svm_ADASYN,bal_acc_svm_ADASYN,precision_svm_ADASYN, recall_svm_ADASYN])\n",
    "    f1_knn_ADASYN,bal_acc_knn_ADASYN,precision_knn_ADASYN, recall_knn_ADASYN,mat_knn_ADASYN=knn(ADASYN_feat,ADASYN_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_ADA.append([f1_knn_ADASYN,bal_acc_knn_ADASYN,precision_knn_ADASYN, recall_knn_ADASYN])\n",
    "    \n",
    "    i=i+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5367 94 40 168\n",
      "balanced accuracy_LR: 0.8952396715169102\n",
      "f1 score_LR: 0.7148936170212766\n",
      "confusion matrix_LR [[5367   94]\n",
      " [  40  168]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4132 1329 4 204\n",
      "balanced accuracy_SVM: 0.8687036045807333\n",
      "f1 score_SVM: 0.23434807581849512\n",
      "confusion matrix_SVM [[4132 1329]\n",
      " [   4  204]]\n",
      "tn, fp, fn, tp: 5402 59 16 192\n",
      "balanced accuracy_KNN: 0.9561365205020214\n",
      "f1 score_KNN: 0.8366013071895425\n",
      "confusion matrix_KNN [[5402   59]\n",
      " [  16  192]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5344 117 21 187\n",
      "balanced accuracy_LR: 0.9388069070190019\n",
      "f1 score_LR: 0.7304687500000001\n",
      "confusion matrix_LR [[5344  117]\n",
      " [  21  187]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4159 1302 1 207\n",
      "balanced accuracy_SVM: 0.8783872177538631\n",
      "f1 score_SVM: 0.2411182294700058\n",
      "confusion matrix_SVM [[4159 1302]\n",
      " [   1  207]]\n",
      "tn, fp, fn, tp: 5390 71 17 191\n",
      "balanced accuracy_KNN: 0.9526339744763568\n",
      "f1 score_KNN: 0.8127659574468085\n",
      "confusion matrix_KNN [[5390   71]\n",
      " [  17  191]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5345 116 22 187\n",
      "balanced accuracy_LR: 0.9367476556250542\n",
      "f1 score_LR: 0.7304687500000001\n",
      "confusion matrix_LR [[5345  116]\n",
      " [  22  187]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4114 1347 1 208\n",
      "balanced accuracy_SVM: 0.8742785948907827\n",
      "f1 score_SVM: 0.23582766439909297\n",
      "confusion matrix_SVM [[4114 1347]\n",
      " [   1  208]]\n",
      "tn, fp, fn, tp: 5389 72 14 195\n",
      "balanced accuracy_KNN: 0.9599149778025827\n",
      "f1 score_KNN: 0.819327731092437\n",
      "confusion matrix_KNN [[5389   72]\n",
      " [  14  195]]\n"
     ]
    }
   ],
   "source": [
    "LR_LoRAS=[]\n",
    "SVM_LoRAS=[]\n",
    "KNN_LoRAS=[]\n",
    "for i in range(3):\n",
    "    \n",
    "    features = training_folds_feats[i]\n",
    "    labels= training_folds_labels[i]\n",
    "    label_1=np.where(labels == 1)[0]\n",
    "    label_1=list(label_1)\n",
    "    features_1_trn=features[label_1]\n",
    "    \n",
    "    label_0=np.where(labels == 0)[0]\n",
    "    label_0=list(label_0)\n",
    "    features_0_trn=features[label_0]\n",
    "    \n",
    "    num_samples=30 \n",
    "    shadow=100\n",
    "    sigma=.005\n",
    "    num_RACOS=(len(features_0_trn)-len(features_1_trn))//len(features_1_trn)\n",
    "    num_afcomb=50\n",
    "    nb_list=Neb_grps(features_1_trn, num_samples)\n",
    "    \n",
    "    LoRAS_1=LoRAS_gen(num_samples,shadow,sigma,num_RACOS,num_afcomb)\n",
    "    LoRAS_train=np.concatenate((LoRAS_1,features_0_trn))\n",
    "    LoRAS_labels=np.concatenate((np.zeros(len(LoRAS_1))+1, np.zeros(len(features_0_trn))))\n",
    "    \n",
    "    f1_lr_LoRAS,bal_acc_lr_LoRAS,precision_lr_LoRAS, recall_lr_LoRAS,mat_lr_LoRAS=lr(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_LoRAS.append([f1_lr_LoRAS,bal_acc_lr_LoRAS,precision_lr_LoRAS, recall_lr_LoRAS])\n",
    "    f1_svm_LoRAS,bal_acc_svm_LoRAS,precision_svm_LoRAS, recall_svm_LoRAS,mat_svm_LoRAS=svm(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_LoRAS.append([f1_svm_LoRAS,bal_acc_svm_LoRAS,precision_svm_LoRAS, recall_svm_LoRAS])\n",
    "    f1_knn_LoRAS,bal_acc_knn_LoRAS,precision_knn_LoRAS, recall_knn_LoRAS,mat_knn_LoRAS=knn(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_LoRAS.append([f1_knn_LoRAS,bal_acc_knn_LoRAS,precision_knn_LoRAS, recall_knn_LoRAS])    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5358 103 39 169\n",
      "balanced accuracy_LR: 0.8968194927668924\n",
      "f1 score_LR: 0.7041666666666667\n",
      "confusion matrix_LR [[5358  103]\n",
      " [  39  169]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4131 1330 5 203\n",
      "balanced accuracy_SVM: 0.8662082001042356\n",
      "f1 score_SVM: 0.23319931074095346\n",
      "confusion matrix_SVM [[4131 1330]\n",
      " [   5  203]]\n",
      "tn, fp, fn, tp: 5415 46 17 191\n",
      "balanced accuracy_KNN: 0.954922932542645\n",
      "f1 score_KNN: 0.8584269662921349\n",
      "confusion matrix_KNN [[5415   46]\n",
      " [  17  191]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5336 125 18 190\n",
      "balanced accuracy_LR: 0.9452859788993281\n",
      "f1 score_LR: 0.7265774378585086\n",
      "confusion matrix_LR [[5336  125]\n",
      " [  18  190]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4111 1350 1 207\n",
      "balanced accuracy_SVM: 0.8739924182665897\n",
      "f1 score_SVM: 0.23456090651558076\n",
      "confusion matrix_SVM [[4111 1350]\n",
      " [   1  207]]\n",
      "tn, fp, fn, tp: 5408 53 18 190\n",
      "balanced accuracy_KNN: 0.9518781781302381\n",
      "f1 score_KNN: 0.8425720620842572\n",
      "confusion matrix_KNN [[5408   53]\n",
      " [  18  190]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 5336 125 20 189\n",
      "balanced accuracy_LR: 0.9407083197164057\n",
      "f1 score_LR: 0.7227533460803058\n",
      "confusion matrix_LR [[5336  125]\n",
      " [  20  189]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\admin\\Anaconda3\\lib\\site-packages\\sklearn\\svm\\_base.py:977: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.\n",
      "  \"the number of iterations.\", ConvergenceWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tn, fp, fn, tp: 4048 1413 1 208\n",
      "balanced accuracy_SVM: 0.8682357455957819\n",
      "f1 score_SVM: 0.2273224043715847\n",
      "confusion matrix_SVM [[4048 1413]\n",
      " [   1  208]]\n",
      "tn, fp, fn, tp: 5410 51 14 195\n",
      "balanced accuracy_KNN: 0.9618377025782648\n",
      "f1 score_KNN: 0.8571428571428571\n",
      "confusion matrix_KNN [[5410   51]\n",
      " [  14  195]]\n"
     ]
    }
   ],
   "source": [
    "LR_tLoRAS=[]\n",
    "SVM_tLoRAS=[]\n",
    "KNN_tLoRAS=[]\n",
    "from sklearn.manifold import TSNE\n",
    "for i in range(3):\n",
    "    \n",
    "    features = training_folds_feats[i]\n",
    "    labels= training_folds_labels[i]\n",
    "    label_1=np.where(labels == 1)[0]\n",
    "    label_1=list(label_1)\n",
    "    features_1_trn=features[label_1]\n",
    "    \n",
    "    label_0=np.where(labels == 0)[0]\n",
    "    label_0=list(label_0)\n",
    "    features_0_trn=features[label_0]\n",
    "    \n",
    "    data_embedded_min = TSNE().fit_transform(features_1_trn)\n",
    "    result_min= pd.DataFrame(data = data_embedded_min, columns = ['t-SNE0', 't-SNE1'])\n",
    "    min_t=np.asmatrix(result_min)\n",
    "    min_t=min_t[0:len(features_1_trn)]\n",
    "    min_t=min_t[:, [0,1]]\n",
    "    \n",
    "    num_samples=30 \n",
    "    shadow=100\n",
    "    sigma=.005\n",
    "    num_RACOS=(len(features_0_trn)-len(features_1_trn))//len(features_1_trn)\n",
    "    num_afcomb=50\n",
    "    nb_list=Neb_grps(min_t, num_samples)\n",
    "    \n",
    "    LoRAS_1=LoRAS_gen(num_samples,shadow,sigma,num_RACOS,num_afcomb)\n",
    "    LoRAS_train=np.concatenate((LoRAS_1,features_0_trn))\n",
    "    LoRAS_labels=np.concatenate((np.zeros(len(LoRAS_1))+1, np.zeros(len(features_0_trn))))\n",
    "    \n",
    "    f1_lr_LoRAS,bal_acc_lr_LoRAS,precision_lr_LoRAS, recall_lr_LoRAS,mat_lr_LoRAS=lr(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    LR_tLoRAS.append([f1_lr_LoRAS,bal_acc_lr_LoRAS,precision_lr_LoRAS, recall_lr_LoRAS])\n",
    "    f1_svm_LoRAS,bal_acc_svm_LoRAS,precision_svm_LoRAS, recall_svm_LoRAS,mat_svm_LoRAS=svm(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    SVM_tLoRAS.append([f1_svm_LoRAS,bal_acc_svm_LoRAS,precision_svm_LoRAS, recall_svm_LoRAS])\n",
    "    f1_knn_LoRAS,bal_acc_knn_LoRAS,precision_knn_LoRAS, recall_knn_LoRAS,mat_knn_LoRAS=knn(LoRAS_train,LoRAS_labels,testing_folds_feats[i],testing_folds_labels[i])\n",
    "    KNN_tLoRAS.append([f1_knn_LoRAS,bal_acc_knn_LoRAS,precision_knn_LoRAS, recall_knn_LoRAS])    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "def stats(arr):\n",
    "    x=np.mean(np.asarray(arr), axis = 0)\n",
    "    y=np.std(np.asarray(arr), axis = 0)\n",
    "    return(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "F1|Balanced Accuracy|precision|recall :: mean|sd\n",
      "Without Oversampling\n",
      "lr: [0.80554941 0.87227307 0.8718189  0.74875782] [0.02844278 0.01270745 0.03542783 0.02437254]\n",
      "svm: [0.78641168 0.85864391 0.86682922 0.72162158] [0.02038688 0.0150965  0.04528814 0.0309472 ]\n",
      "knn: [0.86413214 0.90813205 0.91449762 0.81919396] [0.00026794 0.00394809 0.00986831 0.00829175]\n",
      "SMOTE Oversampling\n",
      "lr: [0.65082612 0.9522395  0.49798208 0.94079714] [0.01135133 0.00741214 0.01789397 0.01770971]\n",
      "svm: [0.19976688 0.84610926 0.11100786 0.99680254] [0.00225522 0.00308712 0.00136569 0.00226097]\n",
      "knn: [0.76676092 0.96284158 0.64508643 0.94558183] [0.01450957 0.00628063 0.01932907 0.01268018]\n",
      "SMOTE-Bl1 Oversampling\n",
      "lr: [0.55922832 0.94828822 0.39591381 0.95199975] [0.00807966 0.00787017 0.00605446 0.01570223]\n",
      "svm: [0.22826859 0.86877349 0.1289464  0.99360508] [0.00062856 0.00124883 0.00039557 0.00224468]\n",
      "knn: [0.72797592 0.96480329 0.58854643 0.95518188] [0.01270637 0.00375826 0.02052823 0.00993992]\n",
      "SMOTE-Bl2 Oversampling\n",
      "lr: [0.46327807 0.94318557 0.30426244 0.97121519] [0.01191001 0.00458165 0.00998839 0.00777592]\n",
      "svm: [0.22826859 0.86877349 0.1289464  0.99360508] [0.00062856 0.00124883 0.00039557 0.00224468]\n",
      "knn: [0.67700108 0.96178581 0.52403542 0.95677678] [0.00633065 0.00494489 0.01114138 0.01183278]\n",
      "SMOTE-SVM Oversampling\n",
      "lr: [0.57489274 0.95147013 0.41137453 0.95518955] [0.01116109 0.00538396 0.01244436 0.01265002]\n",
      "svm: [0.24000592 0.8768573  0.13649233 0.99359741] [0.00312006 0.00152233 0.00206154 0.00227181]\n",
      "knn: [0.75271525 0.96420009 0.62368942 0.95037419] [0.01096151 0.00577625 0.02091084 0.01384824]\n",
      "ADASYN Oversampling\n",
      "lr: [0.54270044 0.9484298  0.37888419 0.95679978] [0.01210011 0.00394307 0.0117247  0.00785154]\n",
      "svm: [0.20553327 0.85132808 0.11458996 0.99680254] [0.0059427  0.00605198 0.00366762 0.00226097]\n",
      "knn: [0.69378196 0.96309815 0.5442311  0.95677678] [0.01211783 0.00738309 0.01115753 0.01420042]\n",
      "LoRAS Oversampling\n",
      "lr: [0.72527704 0.92359808 0.62450489 0.86715587] [0.00734219 0.02007004 0.01184936 0.04208375]\n",
      "svm: [0.23709799 0.87378981 0.13467047 0.99039228] [0.0029062  0.0039684  0.00179457 0.00680453]\n",
      "knn: [0.82289833 0.95622849 0.74142832 0.92478684] [0.01005296 0.00297317 0.0166343  0.0061399 ]\n",
      "tLoRAS Oversampling\n",
      "lr: [0.71783248 0.9276046  0.60880299 0.87675592] [0.00978849 0.02184843 0.00886838 0.04558927]\n",
      "svm: [0.23169421 0.86947879 0.13122797 0.98878972] [0.00314091 0.00329721 0.00207043 0.0090709 ]\n",
      "knn: [0.85271396 0.95621294 0.79349437 0.92158171] [0.00719054 0.00416702 0.00982052 0.00831896]\n"
     ]
    }
   ],
   "source": [
    "print('F1|Balanced Accuracy|precision|recall :: mean|sd')\n",
    "print('Without Oversampling')\n",
    "\n",
    "LR_m, LR_sd=stats(LR)\n",
    "print('lr:',LR_m, LR_sd)\n",
    "SVM_m, SVM_sd=stats(SVM)\n",
    "print('svm:',SVM_m, SVM_sd)\n",
    "KNN_m, KNN_sd= stats(KNN)\n",
    "print('knn:',KNN_m, KNN_sd)\n",
    "\n",
    "print('SMOTE Oversampling')\n",
    "LR_SM_m, LR_SM_sd=stats(LR_SM)\n",
    "print('lr:',LR_SM_m, LR_SM_sd)\n",
    "SVM_SM_m, SVM_SM_sd=stats(SVM_SM)\n",
    "print('svm:',SVM_SM_m, SVM_SM_sd)\n",
    "KNN_SM_m, KNN_SM_sd=stats(KNN_SM)\n",
    "print('knn:',KNN_SM_m, KNN_SM_sd)\n",
    "\n",
    "print('SMOTE-Bl1 Oversampling')\n",
    "LR_SMBL1_m, LR_SMBL1_sd=stats(LR_SMBL1)\n",
    "print('lr:',LR_SMBL1_m, LR_SMBL1_sd)\n",
    "SVM_SMBL1_m,SVM_SMBL1_sd=stats(SVM_SMBL1)\n",
    "print('svm:',SVM_SMBL1_m,SVM_SMBL1_sd)\n",
    "KNN_SMBL1_m,  KNN_SMBL1_sd= stats(KNN_SMBL1)\n",
    "print('knn:',KNN_SMBL1_m,  KNN_SMBL1_sd)\n",
    "\n",
    "print('SMOTE-Bl2 Oversampling')\n",
    "LR_SMBL2_m, LR_SMBL2_sd=stats(LR_SMBL2)\n",
    "print('lr:',LR_SMBL2_m, LR_SMBL2_sd)\n",
    "SVM_SMBL2_m, SVM_SMBL2_sd=stats(SVM_SMBL2)\n",
    "print('svm:',SVM_SMBL2_m, SVM_SMBL2_sd)\n",
    "KNN_SMBL2_m, KNN_SMBL2_sd= stats(KNN_SMBL2)\n",
    "print('knn:',KNN_SMBL2_m, KNN_SMBL2_sd)\n",
    "\n",
    "print('SMOTE-SVM Oversampling')\n",
    "LR_SMSVM_m, LR_SMSVM_sd=stats(LR_SMSVM)\n",
    "print('lr:',LR_SMSVM_m, LR_SMSVM_sd)\n",
    "SVM_SMSVM_m, SVM_SMSVM_sd=stats(SVM_SMSVM)\n",
    "print('svm:',SVM_SMSVM_m, SVM_SMSVM_sd)\n",
    "KNN_SMSVM_m, KNN_SMSVM_sd= stats(KNN_SMSVM)\n",
    "print('knn:',KNN_SMSVM_m, KNN_SMSVM_sd)\n",
    "\n",
    "print('ADASYN Oversampling')\n",
    "LR_ADA_m, LR_ADA_sd=stats(LR_ADA)\n",
    "print('lr:',LR_ADA_m, LR_ADA_sd)\n",
    "SVM_ADA_m, SVM_ADA_sd=stats(SVM_ADA)\n",
    "print('svm:',SVM_ADA_m, SVM_ADA_sd)\n",
    "KNN_ADA_m, KNN_ADA_sd=stats(KNN_ADA)\n",
    "print('knn:',KNN_ADA_m, KNN_ADA_sd)\n",
    "\n",
    "print('LoRAS Oversampling')\n",
    "LR_LoRAS_m, LR_LoRAS_sd=stats(LR_LoRAS)\n",
    "print('lr:',LR_LoRAS_m, LR_LoRAS_sd)\n",
    "SVM_LoRAS_m, SVM_LoRAS_sd=stats(SVM_LoRAS)\n",
    "print('svm:',SVM_LoRAS_m, SVM_LoRAS_sd)\n",
    "KNN_LoRAS_m, KNN_LoRAS_sd=stats(KNN_LoRAS)\n",
    "print('knn:',KNN_LoRAS_m, KNN_LoRAS_sd)\n",
    "\n",
    "print('tLoRAS Oversampling')\n",
    "LR_tLoRAS_m, LR_tLoRAS_sd=stats(LR_tLoRAS)\n",
    "print('lr:',LR_tLoRAS_m, LR_tLoRAS_sd)\n",
    "SVM_tLoRAS_m, SVM_tLoRAS_sd=stats(SVM_tLoRAS)\n",
    "print('svm:',SVM_tLoRAS_m, SVM_tLoRAS_sd)\n",
    "KNN_tLoRAS_m, KNN_tLoRAS_sd=stats(KNN_tLoRAS)\n",
    "print('knn:',KNN_tLoRAS_m, KNN_tLoRAS_sd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
